using JGSY.CMS.LowCode.Platform.Application.DTOs;
using JGSY.CMS.LowCode.Platform.Domain.Entities;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 租户服务接口
    /// 定义租户管理的核心操作
    /// </summary>
    public interface ITenantService
    {
        // 基础CRUD操作
        
        /// <summary>
        /// 创建新租户
        /// </summary>
        /// <param name="request">创建租户请求</param>
        /// <returns>创建的租户实体</returns>
        Task<Tenant> CreateTenantAsync(CreateTenantRequest request);

        /// <summary>
        /// 根据租户ID获取租户
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <returns>租户实体，如果不存在则返回null</returns>
        Task<Tenant?> GetTenantByIdAsync(string tenantId);

        /// <summary>
        /// 获取分页租户列表
        /// </summary>
        /// <param name="request">分页请求参数</param>
        /// <returns>分页结果</returns>
        Task<PagedResult<Tenant>> GetTenantsAsync(GetTenantsRequest request);

        /// <summary>
        /// 更新租户信息
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <param name="request">更新请求</param>
        /// <returns>更新后的租户实体</returns>
        Task<Tenant> UpdateTenantAsync(string tenantId, UpdateTenantRequest request);

        /// <summary>
        /// 删除租户
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <returns>是否成功删除</returns>
        Task<bool> DeleteTenantAsync(string tenantId);

        // 查询操作

        /// <summary>
        /// 根据子域名获取租户
        /// </summary>
        /// <param name="subdomain">子域名</param>
        /// <returns>租户实体</returns>
        Task<Tenant?> GetTenantBySubdomainAsync(string subdomain);

        /// <summary>
        /// 根据自定义域名获取租户
        /// </summary>
        /// <param name="domain">域名</param>
        /// <returns>租户实体</returns>
        Task<Tenant?> GetTenantByDomainAsync(string domain);

        // 验证操作

        /// <summary>
        /// 验证租户是否存在且有效
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <returns>是否有效</returns>
        Task<bool> ValidateTenantAsync(string tenantId);

        /// <summary>
        /// 检查租户是否处于活跃状态
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <returns>是否活跃</returns>
        Task<bool> IsTenantActiveAsync(string tenantId);

        // 状态管理

        /// <summary>
        /// 激活租户
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <returns>是否成功激活</returns>
        Task<bool> ActivateTenantAsync(string tenantId);

        /// <summary>
        /// 暂停租户
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <returns>是否成功暂停</returns>
        Task<bool> SuspendTenantAsync(string tenantId);

        // 配置管理

        /// <summary>
        /// 获取租户配置
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <param name="key">配置键</param>
        /// <returns>配置值</returns>
        Task<string?> GetTenantConfigurationAsync(string tenantId, string key);

        /// <summary>
        /// 设置租户配置
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <param name="key">配置键</param>
        /// <param name="value">配置值</param>
        /// <returns>是否设置成功</returns>
        Task<bool> SetTenantConfigurationAsync(string tenantId, string key, string value);

        // 资源管理

        /// <summary>
        /// 更新租户资源使用量
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <param name="resourceType">资源类型</param>
        /// <param name="usage">使用量</param>
        /// <returns>是否更新成功</returns>
        Task<bool> UpdateTenantResourceUsageAsync(string tenantId, string resourceType, long usage);

        /// <summary>
        /// 获取租户资源使用量
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <param name="resourceType">资源类型</param>
        /// <returns>使用量</returns>
        Task<long> GetTenantResourceUsageAsync(string tenantId, string resourceType);

        /// <summary>
        /// 检查租户资源限制
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <param name="resourceType">资源类型</param>
        /// <param name="requestedUsage">请求使用量</param>
        /// <returns>是否在限制范围内</returns>
        Task<bool> CheckTenantResourceLimitAsync(string tenantId, string resourceType, long requestedUsage);

        // 活动跟踪

        /// <summary>
        /// 记录租户活动
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <returns>是否记录成功</returns>
        Task<bool> RecordTenantActivityAsync(string tenantId);

        // 维护操作

        /// <summary>
        /// 获取已过期的租户列表
        /// </summary>
        /// <returns>过期租户ID列表</returns>
        Task<IEnumerable<string>> GetExpiredTenantsAsync();

        /// <summary>
        /// 获取非活跃租户列表
        /// </summary>
        /// <param name="inactivityThreshold">非活跃时间阈值</param>
        /// <returns>非活跃租户ID列表</returns>
        Task<IEnumerable<string>> GetInactiveTenantsAsync(TimeSpan inactivityThreshold);

        // 统计信息

        /// <summary>
        /// 获取租户统计信息
        /// </summary>
        /// <param name="tenantId">租户ID</param>
        /// <returns>统计信息</returns>
        Task<TenantStatistics> GetTenantStatisticsAsync(string tenantId);

        // 域名验证

        /// <summary>
        /// 验证租户域名
        /// </summary>
        /// <param name="domain">域名</param>
        /// <returns>是否有效</returns>
        Task<bool> ValidateTenantDomainAsync(string domain);
    }
}
